
#include "../common.h"
#include <signal.h>

static void sig_quit(int signo)
{
	printf("caught sig_quit\n");

	if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
	{
		printf("sigquit-sigdfl error\n");
	}
	
	return;
}

int main(int argc, char** argv)
{
	sigset_t newmask, oldmask, pendmask;

	if (signal(SIGQUIT, sig_quit) == SIG_ERR)
	{
		printf("signal-sig_quit error\n");
		return -1;
	}
	
	sigemptyset(&newmask);
	sigaddset(&newmask, SIGQUIT);
	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
	{
		printf("sigprocmask-sig_quit error\n");
		return -1;
	}
	
	sleep(5);

	if (sigpending(&pendmask) < 0)
	{
		printf("sigpending error\n");
		return -1;
	}

	if (sigismember(&pendmask, SIGQUIT))
	{
		printf("sigquit pending\n");
	}

	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
	{
		printf("set oldmask error\n");
		return -1;
	}

	printf("set oldmask, sigquit unblocked \n");

	sleep(5);

	printf("end, return\n");
	return 0;
}
